package com.demo.mapper;

import com.demo.dto.DepartmentPageQueryDTO;
import com.demo.dto.InstructorDTO;
import com.demo.dto.InstructorPageQueryDTO;
import com.demo.pojo.Department;
import com.demo.pojo.Instructor;
import com.demo.vo.InstructorVO;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface InstructorMapper {
    //添加辅导员
    @Insert("insert into sys_instructor(instID,depID,instName,telephone) values (#{instID},(select depID from sys_department where depName=#{depName}),#{instName},#{telephone})")
    void addInstructor(Instructor instructor);

    //删除辅导员信息
    @Delete("delete  from sys_instructor where instID=#{instID}")
    void delete(String instID);

    //分页查询
    @Select("<script>" +
            "SELECT i.instID, i.instName, i.depID, i.telephone, " +
            "d.depName AS depName " +
            "FROM sys_instructor i " +
            "LEFT JOIN sys_department d ON d.depID = i.depID " +
            "WHERE 1=1 " +
            "<if test='instName != null and instName.trim() != \"\"'> " +
            "AND i.instName LIKE CONCAT('%', #{instName}, '%') " +
            "</if> " +
            "<if test='instID != null and instID.trim() != \"\"'> " +
            "AND i.instID = #{instID} " +
            "</if> " +
            "ORDER BY i.instID " +
            "</script>")
    Page<InstructorVO> pageQuery(InstructorPageQueryDTO instructorPageQueryDTO);

    //修改辅导员信息
    @Update("update sys_instructor set instID=#{instID},instName=#{instName},depID=(select depID from sys_department where depName=#{depName}),telephone=#{telephone} where instID=#{instID}")
    void update(InstructorDTO instructorDTO);
}
